class Main extends eui.UILayer {
    
    protected createChildren(): void {
        super.createChildren();

        egret.lifecycle.addLifecycleListener((context) => {
            // custom lifecycle plugin
        })

        egret.lifecycle.onPause = () => {
            egret.ticker.pause();
        }

        egret.lifecycle.onResume = () => {
            egret.ticker.resume();
        }
        //注入自定义的素材解析器
        let assetAdapter = new AssetAdapter();
        egret.registerImplementation("eui.IAssetAdapter", assetAdapter);
        egret.registerImplementation("eui.IThemeAdapter", new ThemeAdapter());

        //适配方式
        //if (!egret.Capabilities.isMobile) {
           // this.stage.scaleMode = egret.StageScaleMode.SHOW_ALL;
        //}
        //初始化
        this.initScene();
        this.initModule();
        //初始化Resource资源加载库
        RES.addEventListener(RES.ResourceEvent.CONFIG_COMPLETE, this.onConfigComplete, this);
        RES.loadConfig("resource/default.res.json", "resource/");
    }
    /**
     * 配置文件加载完成,开始预加载皮肤主题资源和preload资源组。
     */
    private onConfigComplete(event: RES.ResourceEvent): void {
        RES.removeEventListener(RES.ResourceEvent.CONFIG_COMPLETE, this.onConfigComplete, this);
        //加载皮肤主题配置文件,可以手动修改这个文件。替换默认皮肤。
        let theme = new eui.Theme("resource/default.thm.json", this.stage);
        theme.addEventListener(eui.UIEvent.COMPLETE, this.onThemeLoadComplete, this);
        
    }
    /**
     * 主题文件加载完成,开始预加载
     */
    private onThemeLoadComplete(): void {
        App.ResourceUtils.loadGroup("loading", this.onResourceLoadComplete, this.onResourceLoadProgress, this);
        
    }
    private onResourceLoadProgress():void{}
    private onResourceLoadComplete():void{
        App.SceneManager.runScene(SceneConsts.loading);
        new GameStart();//启动游戏
    }
    /**
     * 初始化所有场景
     */
    private initScene():void{
        App.SceneManager.register(SceneConsts.loading, new LoadingScene());
        App.SceneManager.register(SceneConsts.login,new LoginScene());
        App.SceneManager.register(SceneConsts.home, new HomeScene());
    }

    /**
     * 初始化loading模块
     */
    private initModule():void{
        App.ControllerManager.register(ControllerConst.loading, new LoadingController());
    }
}